﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region RPTMaterialCost

        public List<tb_RPT_MaterialCost> GetAllMaterialCost()
        {
            var query = (from obj in this.tb_RPT_MaterialCosts
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }


        public List<tb_RPT_MaterialCost> GetMaterialCostByContition(string strProdCode, string strSlump)
        {
            var tq = from obj in this.tb_RPT_MaterialCosts
                     where obj.IsDelete == 0
                     select obj;

            if (strProdCode.Length > 0)
            {
                tq = tq.Where(entity => entity.ProdCode == strProdCode);
            }

            if (strSlump.Length > 0)
            {
                tq = tq.Where(entity => entity.Slump == strSlump);
            }
           
            var query = tq.ToList();
            return query;
        }

        public tb_RPT_MaterialCost GetMaterialCostById(int id)
        {
            return this.tb_RPT_MaterialCosts.SingleOrDefault(tb_RPT_MaterialCosts => tb_RPT_MaterialCosts.Id == id);
        }

        public void CreateMaterialCost(tb_RPT_MaterialCost entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_RPT_MaterialCosts.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyMaterialCost(tb_RPT_MaterialCost entity)
        {
            tb_RPT_MaterialCost instance = this.tb_RPT_MaterialCosts.SingleOrDefault(p => p.Id == entity.Id);
            instance.ProdCode = entity.ProdCode;
            instance.Slump = entity.Slump;
            instance.WaterBinderRate = entity.WaterBinderRate;
            instance.SandRatio = entity.SandRatio;
            instance.Cement = entity.Cement;
            instance.Water = entity.Water;
            instance.Fine = entity.Fine;
            instance.CoarseSand = entity.CoarseSand;
            instance.Gravel = entity.Gravel;
            instance.Admixture = entity.Admixture;
            instance.Ash = entity.Ash;
            instance.Density = entity.Density;
            instance.Cost = entity.Cost;
            instance.CementPrice = entity.CementPrice;
            instance.WaterPrice = entity.WaterPrice;
            instance.FinePrice = entity.FinePrice;
            instance.CoarseSandPrice = entity.CoarseSandPrice;
            instance.GravelPrice = entity.GravelPrice;
            instance.AdmixturePrice = entity.AdmixturePrice;
            instance.AshPrice = entity.AshPrice;  

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }

        public void DeleteMaterialCost(tb_RPT_MaterialCost entity)
        {
            tb_RPT_MaterialCost deleteEntity = tb_RPT_MaterialCosts.SingleOrDefault(p => p.Id == entity.Id);
            tb_RPT_MaterialCosts.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }
}
